package com.ruoyi.legal.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.legal.domain.PracticeRecordsListView;
import com.ruoyi.legal.service.IPracticeRecordsListViewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * recordsController
 * 
 * @author xiaoxiao
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/legal/records")
public class PracticeRecordsListViewController extends BaseController
{
    @Autowired
    private IPracticeRecordsListViewService practiceRecordsListViewService;

    /**
     * 查询records列表
     */
    @PreAuthorize("@ss.hasPermi('legal:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(PracticeRecordsListView practiceRecordsListView)
    {
        startPage();
        List<PracticeRecordsListView> list = practiceRecordsListViewService.selectPracticeRecordsListViewList(practiceRecordsListView);
        return getDataTable(list);
    }

    /**
     * 导出records列表
     */
    @PreAuthorize("@ss.hasPermi('legal:records:export')")
    @Log(title = "records", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PracticeRecordsListView practiceRecordsListView)
    {
        List<PracticeRecordsListView> list = practiceRecordsListViewService.selectPracticeRecordsListViewList(practiceRecordsListView);
        ExcelUtil<PracticeRecordsListView> util = new ExcelUtil<PracticeRecordsListView>(PracticeRecordsListView.class);
        util.exportExcel(response, list, "records数据");
    }

    /**
     * 获取records详细信息
     */
    @PreAuthorize("@ss.hasPermi('legal:records:query')")
    @GetMapping(value = "/{categoryName}")
    public AjaxResult getInfo(@PathVariable("categoryName") String categoryName)
    {
        return success(practiceRecordsListViewService.selectPracticeRecordsListViewByCategoryName(categoryName));
    }

    /**
     * 新增records
     */
    @PreAuthorize("@ss.hasPermi('legal:records:add')")
    @Log(title = "records", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PracticeRecordsListView practiceRecordsListView)
    {
        return toAjax(practiceRecordsListViewService.insertPracticeRecordsListView(practiceRecordsListView));
    }

    /**
     * 修改records
     */
    @PreAuthorize("@ss.hasPermi('legal:records:edit')")
    @Log(title = "records", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PracticeRecordsListView practiceRecordsListView)
    {
        return toAjax(practiceRecordsListViewService.updatePracticeRecordsListView(practiceRecordsListView));
    }

    /**
     * 删除records
     */
    @PreAuthorize("@ss.hasPermi('legal:records:remove')")
    @Log(title = "records", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryNames}")
    public AjaxResult remove(@PathVariable String[] categoryNames)
    {
        return toAjax(practiceRecordsListViewService.deletePracticeRecordsListViewByCategoryNames(categoryNames));
    }
}
